// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "browser.h"
#include "browserwindow.h"
#include "tabwidget.h"
#include <QApplication>
#include <QLoggingCategory>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
#include <QSslSocket>
#include <QNetworkAccessManager>

using namespace Qt::StringLiterals;

QUrl commandLineUrlArgument()
{
	// const QStringList args = QCoreApplication::arguments();
	// for (const QString &arg : args.mid(1)) {
	//     if (!arg.startsWith(u'-'))
	//         return QUrl::fromUserInput(arg);
	// }
	// return QUrl(u"chrome://qt"_s);
	return QUrl("http://127.0.0.1:9780/design/project/95226218-903d-48e9-8948-cb0ce6266603/template");
	//return QUrl("https://www.google.com/");
}

int main(int argc, char** argv)
{
	qputenv("QT_D3D11_NO_OVERRIDE_SETPRIVATEDATA", "1");
	QCoreApplication::setOrganizationName("QtExamples");

	QApplication app(argc, argv);
	app.setWindowIcon(QIcon(u":AppLogoColor.png"_s));
	QLoggingCategory::setFilterRules("qt.webenginecontext.debug=true");

	qDebug() << "--->" << QWebEngineProfile::defaultProfile();
	QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
	QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, true);

	QUrl url = commandLineUrlArgument();


	QNetworkAccessManager* manager = new QNetworkAccessManager();
	qDebug() << manager->supportedSchemes();
	QSslSocket sslSocket;
	qDebug() << sslSocket.activeBackend();

	qDebug() << QSslSocket::supportsSsl();//是否支持ssl
	qDebug() << QSslSocket::sslLibraryBuildVersionString() << "---" << QSslSocket::sslLibraryVersionString();//依赖的ssl版本


	Browser browser;
	BrowserWindow* window = browser.createHiddenWindow();
	window->tabWidget()->setUrl(url);
	window->show();
	return app.exec();
}
